package Recursive_search_backtracking_algorithm.Topic1_recursive_algorithm.Topic1_recursive_algorithm;

public class pow_x_n {
    //50.Pow(x,n)
    //https://leetcode.cn/problems/powx-n/

    public double myPow(double x, int n) {
        double tmp = 1.0; //

        if (n < 0) {

            for (int i = 0; i < -n; i++) {
                tmp *= x;
            }

            return 1.0 / tmp;

        } else {

            for (int i = 0; i < n; i++) {
                tmp *= x;
            }

            return tmp;
        }
    }
}
